home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / Generic LW "30 sec Alert" / Generic LaserWriter.c < prev    next >
Encoding:
Text File  |  1995-04-10  |  3.8 KB  |  192 lines  |  [TEXT/MPS ]

  1. /*-----------------------------------------------------------------------------
  2.  
  3.     Generic LaserWriter.c
  4.     
  5.         This part of the driver demonstrates how to force the PostScript
  6.         imaging system to copy its output to a file.
  7.         
  8.      12/18/93 - dmh - Removed IIg-dependencies for b3.
  9.         9/13/93 - dmh - Updated for the b2 seed.
  10.         9/14/93 - dmh - Disabled the PostScript log which was created in
  11.                                         the Extensions folder.
  12.         3/22/94 - dmh - Balanced gxInitialize override with a gxShutDown one.
  13.       6/14/94 - dmh - Added the mystical, magical, 30 second alert.
  14.       8/28/94 - dmh - Finalized for SDK.
  15.         
  16.     © 1991-1994 Apple Computer Inc.
  17.     
  18. -----------------------------------------------------------------------------*/
  19.  
  20. // If non-zero, we create a PostScript log in the Extensions folder.
  21.  
  22. #define CREATELOG    0
  23.  
  24. #include <PrintingDrivers.h>
  25. #include <GXExceptions.h>
  26.  
  27. #define    kCreatorType        'scL2'
  28. #define kMyStatID                gxPrintingDriverBaseID
  29.  
  30.  
  31. extern long A5Size (void);
  32. extern void A5Init (void *);
  33.  
  34.  
  35. // Globals...
  36.  
  37. short gLogRefNum;
  38.  
  39.  
  40. OSErr DriverPostScriptDoPageSetup(    gxFormat theFormat,
  41.                                                                          long     pageindx,
  42.                                                                         gxPostScriptImageDataHdl imageDataHdl )
  43. {
  44.     OSErr status;
  45.     char    *setupcommand = "\p%% File For Level-I or Level-II.\n";
  46.     
  47.     require(CREATELOG, Not_Logging);
  48.     status = Send_GXBufferData( & setupcommand[ 1 ], setupcommand[ 0 ], nil );
  49.     nrequire( status, BufferCommandFailed );
  50.     
  51. Not_Logging:
  52.     
  53.     status = Forward_GXPostScriptDoPageSetup( theFormat, pageindx, imageDataHdl );
  54.     ncheck( status );
  55.     
  56. BufferCommandFailed:
  57.     return( status );
  58. }
  59.  
  60.  
  61. OSErr    Do30SecondAlert()
  62. {
  63.     OSErr                        anErr;
  64.     gxStatusRecord    *pStatus;    
  65.     long                        numTicks;
  66.     
  67. // allocate the status record
  68.  
  69.     pStatus = (gxStatusRecord *) NewPtrClear(sizeof(gxStatusRecord));
  70.     anErr = MemError();
  71.  
  72.     if (anErr == noErr ) {
  73.         pStatus->statusOwner        = kCreatorType;
  74.         pStatus->statResId             = kMyStatID;
  75.         pStatus->statResIndex     = 1;
  76.         pStatus->bufferLen            = 0;
  77.  
  78.  
  79. // Tell the Printing Manager to display the 30 second alert
  80.  
  81.         numTicks = TickCount();
  82.  
  83.         do
  84.         {
  85.             anErr = GXAlertTheUser(pStatus);
  86.  
  87.             // wait for 30 seconds.
  88.  
  89.             if ((anErr == noErr) && (pStatus->dialogResult == nil)) {
  90.     
  91.                 Boolean    weBeDone;    
  92.                 
  93.                 weBeDone = (TickCount() - numTicks) >= 30*60;
  94.  
  95.                 if (weBeDone) {
  96.                     pStatus->statResIndex    = 2;
  97.                     anErr = GXAlertTheUser(pStatus);
  98.                     pStatus->dialogResult = ok;
  99.                     
  100.                     }
  101.                 }
  102.                 
  103.             } while ((pStatus->dialogResult == nil) &&  (anErr == noErr));
  104.  
  105.         DisposePtr((Ptr) pStatus);
  106.         }
  107.     return( anErr );
  108. }
  109.  
  110.  
  111. OSErr DriverOpenConnection(void)
  112.     {
  113.         OSErr            status;
  114.                 
  115.         Do30SecondAlert();
  116.         status = Forward_GXOpenConnection();
  117.         nrequire(status, failed_Forward);
  118.         require(CREATELOG, Not_Logging);
  119.  
  120.         status = Create("\pPostScriptLog.ps", 0, 'MPS ', 'TEXT');
  121.         ncheck(status);
  122.         status = FSOpen("\pPostScriptLog.ps", 0, &gLogRefNum);
  123.         ncheck(status);
  124.                     
  125.         status = noErr;
  126.     
  127. Not_Logging:
  128. failed_Forward:
  129.         return(status);    
  130.     
  131.     }//DriverOpenConnection
  132.  
  133.  
  134. OSErr    DriverCloseConnection(void)
  135.     {
  136.         OSErr            status;
  137.         long            j;
  138.         
  139.         status = Forward_GXCloseConnection();
  140.         nrequire(status, failed_Forward);
  141.         require(CREATELOG, Not_Logging);
  142.  
  143.         GetFPos(gLogRefNum, &j);
  144.         SetEOF(gLogRefNum, j);
  145.         FSClose(gLogRefNum);
  146.  
  147. Not_Logging:
  148. failed_Forward:
  149.         return(status);
  150.     }
  151.  
  152.  
  153.  
  154. OSErr    DriverInitialize(void)
  155.     {
  156.         OSErr            status;
  157.         
  158.         status = NewMessageGlobals(A5Size(), A5Init);
  159.         nrequire(status, failed_a5);
  160.  
  161. failed_a5:        
  162.         return(status);
  163.     
  164.     }
  165.  
  166.  
  167. OSErr    DriverShutDown(void)
  168.     {
  169.         DisposeMessageGlobals();
  170.         return noErr;
  171.     }
  172.  
  173.  
  174. OSErr DriverDumpBuffer(gxPrintingBuffer *buffPtr)
  175.     {
  176.         OSErr                status;
  177.         long                count;
  178.                 
  179.         require(CREATELOG, Not_Logging);
  180.         count = buffPtr->size;
  181.         
  182.         status = FSWrite(gLogRefNum, &count, buffPtr->data);
  183.         nrequire(status, failed_Write);
  184.     
  185. Not_Logging:
  186.         status = Forward_GXDumpBuffer(buffPtr);
  187.         ncheck(status);
  188.     
  189. failed_Write:
  190.         return(status);
  191.     
  192.     }